import java.util.Random;
import java.util.Scanner;

public class Test {
    /**
     * 求n的阶乘
     * @param n 5！= 5*4*3*2*1
     * @return
     */
    public static int fac(int n){
        int ret = 1;
        for(int i = 1; i <= n; i++){
            ret = ret * i;
        }
        return ret;
    }

    /**
     * 求n的阶乘的和
     * @param n
     * @return
     */
    public static int facSum(int n){
        int sum = 0;
        for(int i = 1; i <= n; i++){
            sum = sum + fac(i);
        }
        return sum;
    }

    public static void main9(String[] args) {
//        System.out.println(facSum(5));
        int a = 10;
        int b = 20;
        System.out.println("交换前："+a+" "+b);
        int tem = a;
        a = b;
        b = tem;
        System.out.println("交换后："+a+" "+b);
    }

    /*public static void main(String[] args) {
     *//*int ret = sumAdd(10); //方法的调用
        System.out.println(ret);*//*

        System.out.println(sumAdd(10));
        System.out.println(sumAdd(10) * 2); //支持链式调用
        fun(5);
    }

    /**求 1-n的和
     * 函数名字：小驼峰
     * @param n 输入一个数字
     * @return 求的和
     */
    /*public static int sumAdd(int n){    //有返回值
        int sum = 0;
        for (int i = 1; i <= n ; i++) {
            sum = sum + i;
        }
        return sum;
    }
    public static void fun(int n){  //无返回值
        int sum = 0;
        for (int i = 1; i <= n ; i++) {
            sum = sum + i;
        }
        System.out.println(sum);
    }*/

    public static void main8(String[] args) {
        //编写程序数一下 1到 100 的所有整数中出现多少个数字9
        int count = 0;
        for(int i = 1; i <= 100; i++){
            if(i % 10 == 9){
                count++;
            }if(i / 10 == 9){
                count++;
            }
        }
        System.out.println(count);
    }

    //计算1/1-1/2+1/3-1/4+1/5 …… + 1/99 - 1/100 的值 。
    public static void main7(String[] args) {
        double sum = 0.0;
        int flag = 1;
        for(int i = 1; i <= 100; i++){
            sum = sum + 1.0/i * flag;
            flag = -flag;
        }
        System.out.println(sum);
    }

    //给定两个数，求这两个数的最大公约数
    //例如：输入：20 40   输出：20
    public static void main6(String[] args) {
        int a = 20;
        int b = 40;
        int c = a % b; // 20 % 40 == 20
        while (c != 0){
            a = b;  //40
            b = c;  //20
            c = a % b;  //0
        }
        System.out.println("最大公约数为："+b);
    }

    //输出乘法口诀表
    public static void main5(String[] args) {
        for(int i = 1; i <= 9; i++){
            for(int j = 1; j <= i; j++){
                System.out.print(i+"*"+j+"="+i*j+" ");
            }
            System.out.println();
        }
    }

    //    输出 1000 - 2000 之间所有的闰年
    public static void main4(String[] args) {
        for (int year = 1000; year <= 2000; year++) {
            if((year % 4 == 0 && year % 100 != 0) || year % 400 == 0){
                System.out.println(year+"是闰年！");
            }
        }
    }

    //    给定一个数字，判定一个数字是否是素数
    public static void main3(String[] args) {
        /*
        //方法1：
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        for(; i <= n; i++){
            if(n % i == 0){
                System.out.println(n+"不是素数！");
                break;
            }
        }
        //2种情况
        if(i == n){
            System.out.println(n+"是素数！");
        }
         */
        /*
        //方法2：
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        for(; i <= n/2; i++){
            if(n % i == 0){
                System.out.println(n+"不是素数！");
                break;
            }
        }
        //2种情况
        if(i > n/2){
            System.out.println(n+"是素数！");
        }
         */
        //方法3：
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int i = 2;
        for(; i <= Math.sqrt(n); i++){
            if(n % i == 0){
                System.out.println(n+"不是素数！");
                break;
            }
        }
        //2种情况
        if(i > Math.sqrt(n)){
            System.out.println(n+"是素数！");
        }
    }

    //    根据输入的年龄, 来打印出当前年龄的人是少年(低于18), 青年(19-28), 中年(29-55), 老年(56以上)
    public static void main2(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        if(n > 0 && n < 18){
            System.out.println("少年");
        }else if (n >= 18 && n < 29){
            System.out.println("青年");
        }else if (n >= 29 && n < 56){
            System.out.println("中年");
        }else {
            System.out.println("老年");
        }
    }

    public static void main1(String[] args) {
        //猜数字
        Random random = new Random();
//        int rand = random.nextInt(100); //随机数[0-100)
        int rand = random.nextInt(100) + 1; //随机数[1-101)

        Scanner scanner = new Scanner(System.in);

        while (true){
            System.out.println("请输入你要猜的数字：");
            int n = scanner.nextInt();
            if(n < rand){
                System.out.println("猜小了");
            }else if(n == rand){
                System.out.println("猜对了");
            }else{
                System.out.println("猜大了");
            }
        }
    }
}


